package com.dpj.util;

import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.dpj.entity.Catagory;
import com.dpj.entity.DPJMessage;
import com.dpj.entity.Favorite;
import com.dpj.entity.HKBBDTO;
import com.dpj.entity.Merchan;

public class JsonParson {

	public static List<Catagory> getCataList(String json) {
		List<Catagory> list = new ArrayList<Catagory>();
		try {
			JSONArray ja = new JSONArray(json);
			if (ja != null && ja.length() > 0) {
				for (int i = 0; i < ja.length(); i++) {

					JSONObject ja_jo = ja.optJSONObject(i);
					JSONObject jo_app = ja_jo.getJSONObject("APP");
					JSONObject jo_aosc = jo_app
							.optJSONObject("ArrayOfStoreCateDefinition");
					
					if(jo_aosc != null) {
						
						JSONObject jo_scd = jo_aosc
								.optJSONObject("StoreCateDefinition");
						if(jo_scd != null) {
							Catagory c = new Catagory();
							c.setCateGroryName(jo_scd.optString("CateGroryName"));
							c.setStoreCateDefineID(jo_scd
									.optString("StoreCateDefineID"));
							list.add(c);
						} else {
							JSONArray ja_more = jo_aosc.optJSONArray("StoreCateDefinition");
							if(ja_more != null) {
								for(int j = 0; j < ja_more.length(); j++) {
									JSONObject jo_more = ja_more.optJSONObject(j);
									Catagory c_more = new Catagory();
									c_more.setCateGroryName(jo_more.optString("CateGroryName"));
									c_more.setStoreCateDefineID(jo_more
											.optString("StoreCateDefineID"));
									list.add(c_more);
								}
							}
						}
						
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	public static List<Merchan> getMerchanList(String json) {
		List<Merchan> list = new ArrayList<Merchan>();
		try {
			JSONArray ja = new JSONArray(json);
			if (ja != null && ja.length() > 0) {
				for (int i = 0; i < ja.length(); i++) {
					JSONObject ja_jo = ja.optJSONObject(i);
					JSONObject jo_app = ja_jo.optJSONObject("APP");
					JSONObject jo_aos = jo_app.optJSONObject("ArrayOfjsonptest.storedata");
					if(jo_aos != null) {
						
						JSONArray ja_jo_store = jo_aos.optJSONArray("jsonptest.storedata");
						if (ja_jo_store != null && ja_jo_store.length() > 0) {
							for (int j = 0; j < ja_jo_store.length(); j++) {
								JSONObject jo_store = ja_jo_store.optJSONObject(j);
								
								Merchan mc = new Merchan();
								mc.setAddr(jo_store.optString("Addr"));
								mc.setCompanyID(jo_store.optString("CompanyID"));
								mc.setInformation(jo_store.optString("Information"));
								mc.setIntroduction(jo_store
										.optString("Introduction"));
								mc.setLatitude(jo_store.optString("Latitude"));
								mc.setLongtitude(jo_store.optString("Longitude"));
								mc.setModifyTime(jo_store.optString("ModifyTime"));
								mc.setPhone(jo_store.optString("Phone"));
								mc.setSpecialoffers(jo_store
										.optString("Specialoffers"));
								mc.setStatus(jo_store.optString("Status"));
								mc.setStoreID(jo_store.optString("StoreID"));
								mc.setStoreName(jo_store.optString("StoreName"));
								mc.setDistance(jo_store.optString("distance"));
								List<String> imgs = new ArrayList<String>();
								if (jo_store.optString("jpg1") != null
										&& !jo_store.optString("jpg1").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg1"));
								}
								
								if (jo_store.optString("jpg2") != null
										&& !jo_store.optString("jpg2").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg2"));
								}
								
								if (jo_store.optString("jpg3") != null
										&& !jo_store.optString("jpg3").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg3"));
								}
								
								if (jo_store.optString("jpg4") != null
										&& !jo_store.optString("jpg4").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg4"));
								}
								
								if (jo_store.optString("jpg5") != null
										&& !jo_store.optString("jpg5").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg5"));
								}
								
								if (jo_store.optString("jpg6") != null
										&& !jo_store.optString("jpg6").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg6"));
								}
								
								mc.setImgList(imgs);
								
								list.add(mc);
							}
						} else {
							JSONObject jo_one = jo_aos.optJSONObject("jsonptest.storedata");
							
							Merchan mc_one = new Merchan();
							mc_one.setAddr(jo_one.optString("Addr"));
							mc_one.setCompanyID(jo_one.optString("CompanyID"));
							mc_one.setInformation(jo_one.optString("Information"));
							mc_one.setIntroduction(jo_one
									.optString("Introduction"));
							mc_one.setLatitude(jo_one.optString("Latitude"));
							mc_one.setLongtitude(jo_one.optString("Longitude"));
							mc_one.setModifyTime(jo_one.optString("ModifyTime"));
							mc_one.setPhone(jo_one.optString("Phone"));
							mc_one.setSpecialoffers(jo_one
									.optString("Specialoffers"));
							mc_one.setStatus(jo_one.optString("Status"));
							mc_one.setStoreID(jo_one.optString("StoreID"));
							mc_one.setStoreName(jo_one.optString("StoreName"));
							mc_one.setDistance(jo_one.optString("distance"));
							
							List<String> imgs = new ArrayList<String>();
							if (jo_one.optString("jpg1") != null
									&& !jo_one.optString("jpg1").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg1"));
							}
							
							if (jo_one.optString("jpg2") != null
									&& !jo_one.optString("jpg2").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg2"));
							}
							
							if (jo_one.optString("jpg3") != null
									&& !jo_one.optString("jpg3").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg3"));
							}
							
							if (jo_one.optString("jpg4") != null
									&& !jo_one.optString("jpg4").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg4"));
							}
							
							if (jo_one.optString("jpg5") != null
									&& !jo_one.optString("jpg5").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg5"));
							}
							
							if (jo_one.optString("jpg6") != null
									&& !jo_one.optString("jpg6").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg6"));
							}
							
							mc_one.setImgList(imgs);
							
							list.add(mc_one);
							
						}
					}
				}
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}

		return list;
	}
	
	public static List<Merchan> getMerchanListSearch(String json) {
		List<Merchan> list = new ArrayList<Merchan>();
		try {
			JSONArray ja = new JSONArray(json);
			if (ja != null && ja.length() > 0) {
				for (int i = 0; i < ja.length(); i++) {
					JSONObject ja_jo = ja.optJSONObject(i);
					JSONObject jo_app = ja_jo.optJSONObject("APP");
					JSONObject jo_aos = jo_app.optJSONObject("ArrayOfStore");
					if(jo_aos != null) {
						
						JSONArray ja_jo_store = jo_aos.optJSONArray("Store");
						if (ja_jo_store != null && ja_jo_store.length() > 0) {
							for (int j = 0; j < ja_jo_store.length(); j++) {
								JSONObject jo_store = ja_jo_store.optJSONObject(j);
								
								Merchan mc = new Merchan();
								mc.setAddr(jo_store.optString("Addr"));
								mc.setCompanyID(jo_store.optString("CompanyID"));
								mc.setInformation(jo_store.optString("Information"));
								mc.setIntroduction(jo_store
										.optString("Introduction"));
								mc.setLatitude(jo_store.optString("Latitude"));
								mc.setLongtitude(jo_store.optString("Longitude"));
								mc.setModifyTime(jo_store.optString("ModifyTime"));
								mc.setPhone(jo_store.optString("Phone"));
								mc.setSpecialoffers(jo_store
										.optString("Specialoffers"));
								mc.setStatus(jo_store.optString("Status"));
								mc.setStoreID(jo_store.optString("StoreID"));
								mc.setStoreName(jo_store.optString("StoreName"));
								mc.setDistance(jo_store.optString("distance"));
								List<String> imgs = new ArrayList<String>();
								if (jo_store.optString("jpg1") != null
										&& !jo_store.optString("jpg1").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg1"));
								}
								
								if (jo_store.optString("jpg2") != null
										&& !jo_store.optString("jpg2").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg2"));
								}
								
								if (jo_store.optString("jpg3") != null
										&& !jo_store.optString("jpg3").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg3"));
								}
								
								if (jo_store.optString("jpg4") != null
										&& !jo_store.optString("jpg4").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg4"));
								}
								
								if (jo_store.optString("jpg5") != null
										&& !jo_store.optString("jpg5").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg5"));
								}
								
								if (jo_store.optString("jpg6") != null
										&& !jo_store.optString("jpg6").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg6"));
								}
								
								mc.setImgList(imgs);
								
								list.add(mc);
							}
						} else {
							JSONObject jo_one = jo_aos.optJSONObject("Store");
							
							Merchan mc_one = new Merchan();
							mc_one.setAddr(jo_one.optString("Addr"));
							mc_one.setCompanyID(jo_one.optString("CompanyID"));
							mc_one.setInformation(jo_one.optString("Information"));
							mc_one.setIntroduction(jo_one
									.optString("Introduction"));
							mc_one.setLatitude(jo_one.optString("Latitude"));
							mc_one.setLongtitude(jo_one.optString("Longitude"));
							mc_one.setModifyTime(jo_one.optString("ModifyTime"));
							mc_one.setPhone(jo_one.optString("Phone"));
							mc_one.setSpecialoffers(jo_one
									.optString("Specialoffers"));
							mc_one.setStatus(jo_one.optString("Status"));
							mc_one.setStoreID(jo_one.optString("StoreID"));
							mc_one.setStoreName(jo_one.optString("StoreName"));
							mc_one.setDistance(jo_one.optString("distance"));
							
							List<String> imgs = new ArrayList<String>();
							if (jo_one.optString("jpg1") != null
									&& !jo_one.optString("jpg1").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg1"));
							}
							
							if (jo_one.optString("jpg2") != null
									&& !jo_one.optString("jpg2").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg2"));
							}
							
							if (jo_one.optString("jpg3") != null
									&& !jo_one.optString("jpg3").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg3"));
							}
							
							if (jo_one.optString("jpg4") != null
									&& !jo_one.optString("jpg4").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg4"));
							}
							
							if (jo_one.optString("jpg5") != null
									&& !jo_one.optString("jpg5").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg5"));
							}
							
							if (jo_one.optString("jpg6") != null
									&& !jo_one.optString("jpg6").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg6"));
							}
							
							mc_one.setImgList(imgs);
							
							list.add(mc_one);
							
						}
					}
				}
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}

		return list;
	}
	
	public static List<Merchan> getMerchanListClose(String json) {
		List<Merchan> list = new ArrayList<Merchan>();
		try {
			JSONArray ja = new JSONArray(json);
			if (ja != null && ja.length() > 0) {
				for (int i = 0; i < ja.length(); i++) {
					JSONObject ja_jo = ja.optJSONObject(i);
					JSONObject jo_app = ja_jo.optJSONObject("APP");
					JSONObject jo_aos = jo_app.optJSONObject("ArrayOfjsonptest.storedata");
					if(jo_aos != null) {
						
						JSONArray ja_jo_store = jo_aos.optJSONArray("jsonptest.storedata");
						if (ja_jo_store != null && ja_jo_store.length() > 0) {
							for (int j = 0; j < ja_jo_store.length(); j++) {
								JSONObject jo_store = ja_jo_store.optJSONObject(j);
								
								Merchan mc = new Merchan();
								mc.setDistance(jo_store.optString("distance"));
								mc.setAddr(jo_store.optString("Addr"));
								mc.setCompanyID(jo_store.optString("CompanyID"));
								mc.setInformation(jo_store.optString("Information"));
								mc.setIntroduction(jo_store
										.optString("Introduction"));
								mc.setLatitude(jo_store.optString("Latitude"));
								mc.setLongtitude(jo_store.optString("Longitude"));
								mc.setModifyTime(jo_store.optString("ModifyTime"));
								mc.setPhone(jo_store.optString("Phone"));
								mc.setSpecialoffers(jo_store
										.optString("Specialoffers"));
								mc.setStatus(jo_store.optString("Status"));
								mc.setStoreID(jo_store.optString("StoreID"));
								mc.setStoreName(jo_store.optString("StoreName"));
								
								List<String> imgs = new ArrayList<String>();
								if (jo_store.optString("jpg1") != null
										&& !jo_store.optString("jpg1").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg1"));
								}
								
								if (jo_store.optString("jpg2") != null
										&& !jo_store.optString("jpg2").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg2"));
								}
								
								if (jo_store.optString("jpg3") != null
										&& !jo_store.optString("jpg3").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg3"));
								}
								
								if (jo_store.optString("jpg4") != null
										&& !jo_store.optString("jpg4").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg4"));
								}
								
								if (jo_store.optString("jpg5") != null
										&& !jo_store.optString("jpg5").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg5"));
								}
								
								if (jo_store.optString("jpg6") != null
										&& !jo_store.optString("jpg6").equals(
												"null")) {
									imgs.add(jo_store.optString("jpg6"));
								}
								
								mc.setImgList(imgs);
								
								list.add(mc);
							}
						} else {
							JSONObject jo_one = jo_aos.optJSONObject("jsonptest.storedata");
							
							Merchan mc_one = new Merchan();
							mc_one.setAddr(jo_one.optString("Addr"));
							mc_one.setCompanyID(jo_one.optString("CompanyID"));
							mc_one.setInformation(jo_one.optString("Information"));
							mc_one.setIntroduction(jo_one
									.optString("Introduction"));
							mc_one.setLatitude(jo_one.optString("Latitude"));
							mc_one.setLongtitude(jo_one.optString("Longitude"));
							mc_one.setModifyTime(jo_one.optString("ModifyTime"));
							mc_one.setPhone(jo_one.optString("Phone"));
							mc_one.setSpecialoffers(jo_one
									.optString("Specialoffers"));
							mc_one.setStatus(jo_one.optString("Status"));
							mc_one.setStoreID(jo_one.optString("StoreID"));
							mc_one.setStoreName(jo_one.optString("StoreName"));
							
							List<String> imgs = new ArrayList<String>();
							if (jo_one.optString("jpg1") != null
									&& !jo_one.optString("jpg1").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg1"));
							}
							
							if (jo_one.optString("jpg2") != null
									&& !jo_one.optString("jpg2").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg2"));
							}
							
							if (jo_one.optString("jpg3") != null
									&& !jo_one.optString("jpg3").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg3"));
							}
							
							if (jo_one.optString("jpg4") != null
									&& !jo_one.optString("jpg4").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg4"));
							}
							
							if (jo_one.optString("jpg5") != null
									&& !jo_one.optString("jpg5").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg5"));
							}
							
							if (jo_one.optString("jpg6") != null
									&& !jo_one.optString("jpg6").equals(
											"null")) {
								imgs.add(jo_one.optString("jpg6"));
							}
							
							mc_one.setImgList(imgs);
							
							list.add(mc_one);
							
						}
					}
				}
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}

		return list;
	}
	
	public static List<HKBBDTO> getHKBBList(String json) {
		List<HKBBDTO> list = new ArrayList<HKBBDTO>();
			try {
				JSONArray ja = new JSONArray(json);
				if (ja != null && ja.length() > 0) {
					for (int i = 0; i < ja.length(); i++) {
						JSONObject ja_jo = ja.optJSONObject(i);
						JSONObject jo_app = ja_jo.optJSONObject("APP");
						JSONObject jo_aos = jo_app.optJSONObject("ArrayOfStorePromo");
						
						if(jo_aos != null) {
							
							JSONArray ja_jo_store = jo_aos.optJSONArray("StorePromo");
							if (ja_jo_store != null && ja_jo_store.length() > 0) {
								for (int j = 0; j < ja_jo_store.length(); j++) {
									JSONObject jo_store = ja_jo_store.optJSONObject(j);
									HKBBDTO bb = new HKBBDTO();
									bb.setCreater(jo_store.optString("Creater"));
									bb.setCreateTime(jo_store.optString("CreateTime"));
									bb.setJpg1(jo_store.optString("jpg1"));
									bb.setPromoContent(jo_store.optString("PromoContent"));
									bb.setPromoEndDate(jo_store.optString("PromoEndDate"));
									bb.setPromoName(jo_store.optString("PromoName"));
									bb.setPromoStartDate(jo_store.optString("PromoStartDate"));
									bb.setPromoStatus(jo_store.optString("PromoStatus"));
									bb.setStoreID(jo_store.optString("StoreID"));
									bb.setStorePromoID(jo_store.optString("StorePromoID"));
									list.add(bb);
								}
							} else {
								JSONObject jo_one = jo_aos.optJSONObject("StorePromo");
								HKBBDTO bb = new HKBBDTO();
								bb.setCreater(jo_one.optString("Creater"));
								bb.setCreateTime(jo_one.optString("CreateTime"));
								bb.setJpg1(jo_one.optString("jpg1"));
								bb.setPromoContent(jo_one.optString("PromoContent"));
								bb.setPromoEndDate(jo_one.optString("PromoEndDate"));
								bb.setPromoName(jo_one.optString("PromoName"));
								bb.setPromoStartDate(jo_one.optString("PromoStartDate"));
								bb.setPromoStatus(jo_one.optString("PromoStatus"));
								bb.setStoreID(jo_one.optString("StoreID"));
								bb.setStorePromoID(jo_one.optString("StorePromoID"));
								list.add(bb);
							}
							
						}
						
						
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
			
		return list;
	}
	
	public static List<HKBBDTO> getHKBBListUpdate(String json) {
		List<HKBBDTO> list = new ArrayList<HKBBDTO>();
			try {
				JSONArray ja = new JSONArray(json);
				if (ja != null && ja.length() > 0) {
					for (int i = 0; i < ja.length(); i++) {
						JSONObject ja_jo = ja.optJSONObject(i);
						JSONObject jo_app = ja_jo.optJSONObject("APP");
						JSONObject jo_aos = jo_app.optJSONObject("ArrayOfjsonptest.storepromo");
						
						if(jo_aos != null) {
							
							JSONArray ja_jo_store = jo_aos.optJSONArray("jsonptest.storepromo");
							if (ja_jo_store != null && ja_jo_store.length() > 0) {
								for (int j = 0; j < ja_jo_store.length(); j++) {
									JSONObject jo_store = ja_jo_store.optJSONObject(j);
									HKBBDTO bb = new HKBBDTO();
									bb.setCreater(jo_store.optString("Creater"));
									bb.setCreateTime(jo_store.optString("CreateTime"));
									bb.setJpg1(jo_store.optString("jpg1"));
									bb.setPromoContent(jo_store.optString("PromoContent"));
									bb.setPromoEndDate(jo_store.optString("PromoEndDate"));
									bb.setPromoName(jo_store.optString("PromoName"));
									bb.setPromoStartDate(jo_store.optString("PromoStartDate"));
									bb.setPromoStatus(jo_store.optString("PromoStatus"));
									bb.setStoreID(jo_store.optString("StoreID"));
									bb.setStorePromoID(jo_store.optString("StorePromoID"));
									bb.setStoreName(jo_store.optString("StoreName"));
									bb.setStoreLogo(jo_store.optString("StoreLogo"));
									
									bb.setAddr(jo_store.optString("Addr"));
									bb.setCompanyID(jo_store.optString("CompanyID"));
									bb.setLatitude(jo_store.optString("Latitude"));
									bb.setLongtitude(jo_store.optString("Longitude"));
									bb.setPhone(jo_store.optString("Phone"));
									list.add(bb);
								}
							} else {
								JSONObject jo_one = jo_aos.optJSONObject("StorePromo");
								HKBBDTO bb = new HKBBDTO();
								bb.setCreater(jo_one.optString("Creater"));
								bb.setCreateTime(jo_one.optString("CreateTime"));
								bb.setJpg1(jo_one.optString("jpg1"));
								bb.setPromoContent(jo_one.optString("PromoContent"));
								bb.setPromoEndDate(jo_one.optString("PromoEndDate"));
								bb.setPromoName(jo_one.optString("PromoName"));
								bb.setPromoStartDate(jo_one.optString("PromoStartDate"));
								bb.setPromoStatus(jo_one.optString("PromoStatus"));
								bb.setStoreID(jo_one.optString("StoreID"));
								bb.setStorePromoID(jo_one.optString("StorePromoID"));
								bb.setStoreName(jo_one.optString("StoreName"));
								bb.setStoreLogo(jo_one.optString("StoreLogo"));
								bb.setAddr(jo_one.optString("Addr"));
								bb.setCompanyID(jo_one.optString("CompanyID"));
								bb.setLatitude(jo_one.optString("Latitude"));
								bb.setLongtitude(jo_one.optString("Longitude"));
								bb.setPhone(jo_one.optString("Phone"));
								
								list.add(bb);
							}
							
						}
						
						
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
			
		return list;
	}
	
	public static List<Favorite> getFavList(String json) {
		List<Favorite> list = new ArrayList<Favorite>();
		try {
			JSONArray ja = new JSONArray(json);
			if (ja != null && ja.length() > 0) {
				for (int i = 0; i < ja.length(); i++) {
					JSONObject ja_jo = ja.optJSONObject(i);
					JSONObject jo_app = ja_jo.optJSONObject("APP");
					JSONObject jo_aos = jo_app.optJSONObject("ArrayOfjsonptest.mystore");
					
					if(jo_aos != null) {
						
						JSONArray ja_jo_store = jo_aos.optJSONArray("jsonptest.mystore");
						if (ja_jo_store != null && ja_jo_store.length() > 0) {
							for (int j = 0; j < ja_jo_store.length(); j++) {
								JSONObject jo_store = ja_jo_store.optJSONObject(j);
								Favorite fav = new Favorite();
								fav.setCreateTime(jo_store.optString("CreateTime"));
								fav.setFavoriteID(jo_store.optString("FavoriteID"));
								fav.setStoreID(jo_store.optString("StoreID"));
								fav.setUID(jo_store.optString("UID"));
								fav.setUserMemo(jo_store.optString("UserMemo"));
								fav.setStoreLogo(jo_store.optString("StoreLogo"));
								fav.setStoreName(jo_store.optString("StoreName"));
								fav.setAddr(jo_store.optString("Addr"));
								fav.setJpg1(jo_store.optString("jpg1"));
								fav.setLatitude(jo_store.optString("Latitude"));
								fav.setLongitude(jo_store.optString("Longitude"));
								fav.setPhone(jo_store.optString("Phone"));
								list.add(fav);
							}
						} else {
//							JSONObject jo_one = jo_aos.optJSONObject("UserFavorite");
							JSONObject jo_one = jo_aos.optJSONObject("jsonptest.mystore");
							Favorite fav = new Favorite();
							fav.setCreateTime(jo_one.optString("CreateTime"));
							fav.setFavoriteID(jo_one.optString("FavoriteID"));
							fav.setStoreID(jo_one.optString("StoreID"));
							fav.setUID(jo_one.optString("UID"));
							fav.setUserMemo(jo_one.optString("UserMemo"));
							fav.setStoreLogo(jo_one.optString("StoreLogo"));
							fav.setStoreName(jo_one.optString("StoreName"));
							fav.setAddr(jo_one.optString("Addr"));
							fav.setJpg1(jo_one.optString("jpg1"));
							fav.setLatitude(jo_one.optString("Latitude"));
							fav.setLongitude(jo_one.optString("Longitude"));
							fav.setPhone(jo_one.optString("Phone"));
							list.add(fav);
						}
						
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public static List<DPJMessage> getMessageList(String json) {
		List<DPJMessage> list = new ArrayList<DPJMessage>();
		try {
			JSONArray ja = new JSONArray(json);
			if (ja != null && ja.length() > 0) {
				for (int i = 0; i < ja.length(); i++) {
					JSONObject ja_jo = ja.optJSONObject(i);
					JSONObject jo_app = ja_jo.optJSONObject("APP");
					JSONObject jo_aos = jo_app.optJSONObject("ArrayOfMessage");
					
					if(jo_aos != null) {
						
						JSONObject jo_store = jo_aos.optJSONObject("Message");
//					if (ja_jo_store != null && ja_jo_store.length() > 0) {
//						for (int j = 0; j < ja_jo_store.length(); j++) {
//							JSONObject jo_store = ja_jo_store.optJSONObject(j);
						
						if(jo_store != null) {
							DPJMessage dMessage = new DPJMessage();
							dMessage.setCreater(jo_store.optString("Creater"));
							dMessage.setCreateTime(jo_store.optString("CreateTime"));
							dMessage.setDeclareType(jo_store.optString("DeclareType"));
							dMessage.setMessageContent(jo_store.optString("MessageContent"));
							dMessage.setMessageEndDate(jo_store.optString("MessageEndDate"));
							dMessage.setMessageID(jo_store.optString("MessageID"));
							dMessage.setMessageStartDate(jo_store.optString("MessageStartDate"));
							dMessage.setMessageStatus(jo_store.optString("MessageStatus"));
							dMessage.setMessageSubject(jo_store.optString("MessageSubject"));
							dMessage.setMessageType(jo_store.optString("MessageType"));
							dMessage.setSender(jo_store.optString("Sender"));
							list.add(dMessage);
							
						} else {
							JSONArray ja_more = jo_aos.optJSONArray("Message");
							if(ja_more != null) {
								for(int j = 0; j < ja_more.length(); j++) {
									JSONObject jo_more = ja_more.optJSONObject(j);
									DPJMessage dMessage_more = new DPJMessage();
									dMessage_more.setCreater(jo_more.optString("Creater"));
									dMessage_more.setCreateTime(jo_more.optString("CreateTime"));
									dMessage_more.setDeclareType(jo_more.optString("DeclareType"));
									dMessage_more.setMessageContent(jo_more.optString("MessageContent"));
									dMessage_more.setMessageEndDate(jo_more.optString("MessageEndDate"));
									dMessage_more.setMessageID(jo_more.optString("MessageID"));
									dMessage_more.setMessageStartDate(jo_more.optString("MessageStartDate"));
									dMessage_more.setMessageStatus(jo_more.optString("MessageStatus"));
									dMessage_more.setMessageSubject(jo_more.optString("MessageSubject"));
									dMessage_more.setMessageType(jo_more.optString("MessageType"));
									dMessage_more.setSender(jo_more.optString("Sender"));
									list.add(dMessage_more);
								}
							}
						}
						
//						}
//					}
					}
					
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
}
